﻿public partial class Solution
{
    public int[] TwoSum(int[] nums, int target)
    {
        // 用字典存储值和索引关系，查找比较快
        // dict结构：<值，索引>
        Dictionary<int, int> dict = new Dictionary<int, int>();
        int[] result = new int[2];
        for (int i = 0; i < nums.Length; i++)
        {
            if (dict.ContainsKey(target - nums[i]))
            {
                result[0] = dict[target - nums[i]];
                result[1] = i;
            }
            dict[nums[i]] = i;
        }
        return result;
    }
}
